package com.bjsxt.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjsxt.domain.User;
import com.bjsxt.domain.UserAuthAuditRecord;
import com.bjsxt.domain.UserAuthInfo;
import com.bjsxt.dto.*;
import com.bjsxt.feign.UserFeignClient;
import com.bjsxt.model.Result;
import com.bjsxt.model.UserAuthInfoVo;
import com.bjsxt.model.UserVo;
import com.bjsxt.service.UserAuthAuditRecordService;
import com.bjsxt.service.UserAuthInfoService;
import com.bjsxt.service.UserService;
import com.bjsxt.util.SpringSecurityUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * description:
 * 用户中心控制层
 * 用户中心的权限:
 * 查询： user_query
 * 修改： user_update
 *
 * @author ALIENWARE <br />
 * @date 2021/8/8
 */
@RestController
@RequestMapping("/users")
@Api(tags = "用户中心控制器")
public class UserController implements UserFeignClient {

    /**
     * 用户中心业务层接口
     */
    @Autowired
    private UserService userService;

    /**
     * 用户审核记录业务层接口
     */
    @Autowired
    private UserAuthAuditRecordService userAuthAuditRecordService;

    /**
     * 用户实名认证业务层接口
     */
    @Autowired
    private UserAuthInfoService userAuthInfoService;

    /**
     * 会员列表分页查询
     *
     * @param page     分页对象<User>
     * @param mobile   手机号
     * @param userId   会员的 id, 精确查询
     * @param userName 用户名
     * @param realName 真实姓名
     * @param status   状态 0: 禁用 1: 启用
     * @return 统一响应对象
     */
    @GetMapping
    @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "会员列表分页查询", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", paramType = "query", example = "13956844562"),
            @ApiImplicitParam(name = "userId", value = "会员的 id, 精确查询", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "realName", value = "真实姓名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "status", value = "状态 0: 禁用 1: 启用", dataType = "Integer", paramType = "query", example = "1")
    })
    public Result<Page<User>> findByPage(
            @ApiIgnore Page<User> page,
            String mobile,
            Long userId,
            String userName,
            String realName,
            Integer status
    ) {
        // 查询时间, 我们讲最近新增的, 修改的数据优先展示, 排序 last_update_time
        page.addOrder(OrderItem.desc(User.COL_LAST_UPDATE_TIME));
        // 调用业务层进行分页数据的查询
        Page<User> userPage = userService.pageByMobileAndUserIdAndUserNameAndRealNameAndStatusAndReviewsStatus(page, mobile, userId, userName, realName, status, null);
        // 返回响应数据
        return Result.success(userPage);
    }

    /**
     * 根据用户的 id 集合查询用户基本数据
     *
     * @param ids 用户 id 集合
     * @return 查询出的用户基本数据
     */
    @Override
    // @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "查询用户基本数据", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "会员 Id 集合", dataType = "Long", paramType = "query", example = "1")
    })
    public List<UserDto> getBasicUsers(List<Long> ids) {
        // 调用业务层进行数据的查询并返回
        return userService.listBasicByIds(ids);
    }

    /**
     * 根据用户 id 集合或者用户名或者手机号进行查询用户数据
     *
     * @param ids      用户 id 集合
     * @param userName 用户名
     * @param mobile   手机号码
     * @return key: 用户数据的 id，value: 查询出的用户基本数据
     */
    @Override
    // @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "查询用户基本数据", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "会员 Id 集合", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", paramType = "query", example = "13956844562")
    })
    public Map<Long, UserDto> getBasicUsersMap(List<Long> ids, String userName, String mobile) {
        // 调用业务层进行数据的查询并返回
        return userService.listBasicByIdsAndUserNameAndMobile(ids, userName, mobile);
    }

    /**
     * 获取当前登录的用户详情
     *
     * @return 统一响应对象
     */
    @GetMapping("/current/info")
    // TODO: 这个地方不需要权限认证, 这个方法是用户方法
    // @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "获取用户的详情", authorizations = {@Authorization("Authorization")})
    public Result<UserVo> getCurrentUserInfo() {
        // 查询当前用户的数据信息
        UserVo user = userService.getUserVoById(SpringSecurityUtils.getCurrentUserId());
        // 返回当前用户对象数据
        return Result.success(user);
    }

    /**
     * 根据用户的 id 查询用户的详情数据
     *
     * @param id 用户的 id
     * @return 统一响应对象
     */
    @GetMapping("/info")
    @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "获取用户的详情", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "会员 Id", dataType = "Long", required = true, paramType = "query", example = "1")
    })
    public Result<UserVo> getUserInfo(@NotNull Long id) {
        // 查询用户的数据信息
        UserVo user = userService.getUserVoById(id);
        // 返回用户对象数据
        return Result.success(user);
    }

    /**
     * 更新用户数据
     *
     * @param user 用户数据对象
     * @return 统一响应对象
     */
    @PatchMapping
    @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "更新用户数据", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user", value = "User 的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> update(@RequestBody @Validated User user) {
        // 调用业务层方法进行数据的保存
        boolean flag = userService.updateById(user);
        // 如果为 true 更新成功
        if (flag) return Result.success("更新成功");
        // 如果为 false 更新失败
        return Result.fail("更新失败");
    }

    /**
     * 启用/禁用一个用户
     *
     * @param id     要启用/禁用一个会员 Id
     * @param status 要设置的会员状态值 1: 启用 0: 禁用
     * @return 统一响应对象
     */
    @PostMapping("/status")
    @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "启用/禁用一个用户", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要启用/禁用一个会员 Id", dataType = "Long", required = true, paramType = "query", example = "1"),
            @ApiImplicitParam(name = "status", value = "要设置的会员状态值 1: 启用 0: 禁用", dataType = "Byte", paramType = "query", example = "0")
    })
    public Result<Void> updateStatus(@NotNull Long id, Byte status) {
        // 创建更新的 user 对象
        User user = new User();
        // 设置 id 及需要更新的值
        user.setId(id);
        user.setStatus(status);
        // 调用业务层方法进行数据的保存
        boolean flag = userService.updateById(user);
        // 如果为 true 更新成功
        if (flag) return Result.success("更新成功");
        // 如果为 false 更新失败
        return Result.fail("更新失败");
    }

    /**
     * 修改用户手机号
     *
     * @param updatePhone 修改用户手机号的参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/updatePhone")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "修改用户手机号", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "updatePhone", value = "修改用户手机号的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> updatePhone(@Validated @RequestBody UpdatePhoneDto updatePhone) {
        // 获取当前用的 id 值
        Long userId = SpringSecurityUtils.getCurrentUserId();
        //调用业务层方法进行修改
        boolean flag = userService.updatePhone(userId, updatePhone);
        // 如果为 true 修改成功
        if (flag) return Result.success("修改成功");
        // 如果为 false 修改失败
        return Result.fail("修改失败");
    }

    /**
     * 修改用户登录密码
     *
     * @param updatePassword 修改用户登录密码参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/updateLoginPassword")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "修改用户登录密码", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "updatePassword", value = "修改用户密码的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> updateLoginPassword(@Validated @RequestBody UpdatePasswordDto updatePassword) {
        // 获取当前用的 id 值
        Long userId = SpringSecurityUtils.getCurrentUserId();
        //调用业务层方法进行修改
        boolean flag = userService.updateLoginPassword(userId, updatePassword);
        // 如果为 true 修改成功
        if (flag) return Result.success("修改成功");
        // 如果为 false 修改失败
        return Result.fail("修改失败");
    }

    /**
     * 找回用户登录密码
     *
     * @param setPasswordDto 找回用户的密码的参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/setPassword")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "找回用户登录密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "setPasswordDto", value = "找回用户密码的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> setPassword(@Validated @RequestBody SetPasswordDto setPasswordDto) {
        //调用业务层方法进行找回
        boolean flag = userService.setLoginPassword(setPasswordDto);
        // 如果为 true 找回成功
        if (flag) return Result.success("找回成功");
        // 如果为 false 找回失败
        return Result.fail("找回失败");
    }

    /**
     * 修改用户支付密码
     *
     * @param updatePassword 修改用户支付密码参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/updatePayPassword")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "修改用户支付密码", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "updatePassword", value = "修改用户支付密码的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> updatePayPassword(@Validated @RequestBody UpdatePasswordDto updatePassword) {
        // 获取当前用的 id 值
        Long userId = SpringSecurityUtils.getCurrentUserId();
        //调用业务层方法进行修改
        boolean flag = userService.updatePayPassword(userId, updatePassword);
        // 如果为 true 修改成功
        if (flag) return Result.success("修改成功");
        // 如果为 false 修改失败
        return Result.fail("修改失败");
    }

    /**
     * 重置用户支付密码
     *
     * @param resetPayPassword 重置用户密码的参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/setPayPassword")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "重置用户支付密码", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resetPayPassword", value = "重置用户支付密码的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> resetPayPassword(@Validated @RequestBody ResetPayPasswordDto resetPayPassword) {
        // 获取当前用的 id 值
        Long userId = SpringSecurityUtils.getCurrentUserId();
        //调用业务层方法进行重置
        boolean flag = userService.resetPayPassword(userId, resetPayPassword);
        // 如果为 true 重置成功
        if (flag) return Result.success("重置成功");
        // 如果为 false 重置失败
        return Result.fail("重置失败");
    }


    // ============================用户相关操作完毕================================

    /**
     * 查询用户的审核列表
     *
     * @param page          分页对象<User>
     * @param mobile        手机号
     * @param userId        会员的 id, 精确查询
     * @param userName      用户名
     * @param realName      真实姓名
     * @param reviewsStatus 审核状态,1通过,2拒绝,0,待审核
     * @return 统一响应对象
     */
    @GetMapping("/auths")
    @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "查询用户的审核列表", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", paramType = "query", example = "13956844562"),
            @ApiImplicitParam(name = "userId", value = "会员的 id, 精确查询", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "realName", value = "真实姓名", dataType = "String", paramType = "query", example = "张三"),
            @ApiImplicitParam(name = "reviewsStatus", value = "审核状态,1通过,2拒绝,0,待审核", dataType = "Integer", paramType = "query", example = "0")
    })
    public Result<Page<User>> findAuthByPage(
            @ApiIgnore Page<User> page,
            String mobile,
            Long userId,
            String userName,
            String realName,
            Integer reviewsStatus
    ) {
        // 查询时间, 我们讲最近新增的, 修改的数据优先展示, 排序 last_update_time
        page.addOrder(OrderItem.desc(User.COL_LAST_UPDATE_TIME));
        // 调用业务层进行分页数据的查询
        Page<User> userPage = userService.pageByMobileAndUserIdAndUserNameAndRealNameAndStatusAndReviewsStatus(page, mobile, userId, userName, realName, null, reviewsStatus);
        // 返回响应数据
        return Result.success(userPage);
    }

    /**
     * 查询用户的认证的详情数据
     *
     * @param id 会员的 id, 精确查询
     * @return 统一响应对象
     */
    @GetMapping("/auth/info")
    @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "查询用户的认证详情", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "会员 Id", dataType = "Long", required = true, paramType = "query", example = "1")
    })
    public Result<UserAuthInfoVo> getUserAuthInfo(@NotNull Long id) {
        //根据会员的 id 查询会员数据
        User user = userService.getById(id);
        //创建用户的审核记录集合
        List<UserAuthAuditRecord> userAuthAuditRecords = Collections.EMPTY_LIST;
        //创建用户的实名认证信息集合
        List<UserAuthInfo> userAuthInfos = Collections.EMPTY_LIST;
        //如果查询的会员不是空
        if (user != null) {
            // 获取用户的审核状态
            Byte reviewsStatus = user.getReviewsStatus();
            // 如果用户的审核状态是未审核
            if (reviewsStatus == null || reviewsStatus == 0)
                //根据用户 id 查询用户实名认证信息
                userAuthInfos = userAuthInfoService.getByUserId(id);
            else { //如果审核的状态是通过或者未通过
                // 查询用户的审核记录
                userAuthAuditRecords = userAuthAuditRecordService.getUserAuthAuditRecordList(id);
                //获取最新认证的审核记录
                UserAuthAuditRecord userAuthAuditRecord = userAuthAuditRecords.get(0);
                //根据认证的唯一标识查询认证信息
                userAuthInfos = userAuthInfoService.getByAuthCode(userAuthAuditRecord.getAuthCode());
            }
        }
        //返回响应数据
        return Result.success(new UserAuthInfoVo(user, userAuthAuditRecords, userAuthInfos));
    }


    /**
     * 审核
     * 对用户高级认证进行审核
     * 审核就是对一组图片唯一 code 的认可,符合条件,审核通过
     *
     * @param id            会员的 id
     * @param reviewsStatus 审核状态,1通过,2拒绝,0,待审核
     * @param authCode      一组图片的唯一标识
     * @param remark        审核拒绝的原因(非必填)
     * @return 统一响应对象
     */
    @PostMapping("/auths/status")
    @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "审核", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "会员 Id", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "reviewsStatus", value = "审核状态,1通过,2拒绝,0,待审核", dataType = "Byte", required = true, paramType = "query", example = "0"),
            @ApiImplicitParam(name = "authCode", value = "一组图片的唯一标识", dataType = "Long", required = true, paramType = "query", example = "1"),
            @ApiImplicitParam(name = "remark", value = "审核拒绝的原因(非必填)", dataType = "String", paramType = "query", example = "图片有遮挡")
    })
    public Result<Void> updateAuthStatus(@NotNull Long id, @NotNull Byte reviewsStatus, @NotNull Long authCode, @RequestParam(required = false) String remark) {
        //调用业务层方法进行审核
        boolean flag = userService.audit(id, reviewsStatus, authCode, remark);
        // 如果为 true 审核成功
        if (flag) return Result.success("审核成功");
        // 如果为 false 审核失败
        return Result.fail("审核失败");
    }

    /**
     * 用户的实名认证
     *
     * @param identify 用户实名认证数据对象
     * @return 统一响应对象
     */
    @PostMapping("/authAccount")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "用户的实名认证", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "identify", value = "用户实名认证的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> identifyCheck(@RequestBody @Validated IdentifyDto identify) {
        // 获取当前用户的 id 数据
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 调用业务层代码进行用户的真实身份认证
        boolean flag = userService.identifyValidate(userId, identify);
        if (flag) return Result.success("认证成功");
        // 如果为 false 审核失败
        return Result.fail("认证失败");
    }

    /**
     * 用户高级实名认证
     *
     * @param imgs 用户身份证图片路径集合
     * @return 统一响应对象
     */
    @PostMapping("/authUser")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "用户高级实名认证", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "imgs", value = "用户实名认证身份证照片 json 数组，内容是图片的地址", dataType = "String", paramType = "body", example = "[]")
    })
    public Result<Void> authUser(@RequestBody @NotEmpty List<String> imgs) {
        // 获取当前的用户 id
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 调用业务层进行对用户进行高级实名认证
        boolean flag = userService.authUser(userId, imgs);
        if (flag) return Result.success("上传成功，请等待审核结果。");
        // 如果为 false 审核失败
        return Result.fail("上传失败，请重新上传。");
    }

    // ============================用户认证操作完毕================================

    /**
     * 直接查询该用户邀请的用户列表
     *
     * @param page   分页对象<User>
     * @param userId 用户的 id
     * @return 统一响应对象
     */
    @GetMapping("/directInvites")
    @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "直接查询该用户邀请的用户列表", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", dataType = "Long", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页条数", dataType = "Long", paramType = "query", example = "20"),
            @ApiImplicitParam(name = "userId", value = "用户 Id", dataType = "Long", required = true, paramType = "query", example = "1")
    })
    public Result<Page<User>> getDirectInvites(@ApiIgnore Page<User> page, @NotNull Long userId) {
        // 调用业务层进行分页数据的查询
        Page<User> userPage = userService.pageDirectInvitesByUserId(page, userId);
        // 返回响应数据
        return Result.success(userPage);
    }

    /**
     * 获取用户的邀请成员列表
     *
     * @return 统一响应对象
     */
    @GetMapping("/invites")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "获取用户的邀请成员列表", authorizations = {@Authorization("Authorization")})
    public Result<List<User>> getUserInvites() {
        // 获取当前用户 ID
        Long userId = SpringSecurityUtils.getCurrentUserId();
        // 根据 ID 调用业务层查询用户邀请的用户集合
        List<User> invitesUsers = userService.getUserInvites(userId);
        // 返回用户的邀请列表数据
        return Result.success(invitesUsers);
    }

    // ============================用户邀请操作完毕================================

    /**
     * 检测用户手机号的可用状态，可用则进行发送验证码
     *
     * @param countryCode  电话的国家区号
     * @param mobile       需要验证的手机号
     * @param templateCode 短信模板ID
     * @return 统一响应对象
     */
    @GetMapping("/checkTel")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "检查手机号可用状态，并发送验证码", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "countryCode", value = "电话的国家区号", dataType = "String", required = true, paramType = "query", example = "+86"),
            @ApiImplicitParam(name = "mobile", value = "需要验证的手机号", dataType = "String", required = true, paramType = "query", example = "17756955362"),
            @ApiImplicitParam(name = "templateCode", value = "短信模板 ID", dataType = "String", required = true, paramType = "query", example = "CHANGE_PHONE_VERIFY")
    })
    public Result<Void> checkPhone(@NotBlank String countryCode, @NotBlank String mobile, @NotBlank String templateCode) {
        // 调用业务层代码进行用户的真实身份认证
        boolean flag = userService.checkPhone(countryCode, mobile, templateCode);
        // 如果是 true 校验成功
        if (flag) return Result.success("校验成功");
        // 如果为 false 校验失败
        return Result.fail("校验失败，手机号不可用");
    }

    /**
     * 注册一名用户
     *
     * @param registerDto 注册用户的参数实体对象
     * @return 统一响应对象
     */
    @PostMapping("/register")
    // @PreAuthorize("hasAuthority('user_update')")
    @ApiOperation(value = "注册用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "registerDto", value = "注册用户的实体 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> register(@Validated @RequestBody RegisterDto registerDto) {
        // 调用业务层代码进行用户的注册
        boolean flag = userService.register(registerDto);
        // 如果是 true 注册成功
        if (flag) return Result.success("注册成功");
        // 如果为 false 注册失败
        return Result.fail("注册失败");
    }
}
